//
var yuan = new Date().getFullYear();
var Month = new Date().getMonth() + 1;
console.log(Month);

document.querySelector("#year").innerHTML = yuan;
document.querySelector("#month").innerHTML = Month;



//判断这一年是不是闰年
function wn(y){
    if (y % 400 ===0 || (y % 4 ===0 && y % 100 !== 0)){
        return true;
    }else {
        return false;
    }
}

//总天数
var q = 0;

//从1980年到2018一共多少天
for (var i=1980 ; i<yuan ; i++){
    if (wn(i)){
        q += 366;
    }else {
        q += 365;
    }
}
console.log(q);


//算出今年1月到本月的上个月一共多少天

for (var j=1 ; j<Month ; j++){
    switch (j){
        case 1:
            q += 31;
            break;
        case 2:
            if (wn(j)){
                q += 29;
            }else {
                q += 28;
            }
            break;
        case 3:
            q += 31;
            break;
        case 4:
            q += 30;
            break;
        case 5:
            q += 31;
            break;
        case 6:
            q += 30;
            break;
        case 7:
            q += 31;
            break;
        case 8:
            q += 31;
            break;
        case 9:
            q += 30;
            break;
        case 10:
            q += 31;
            break;
        case 11:
            q += 30;
            break;
        case 12:
            q += 31;
            break;
    }
}
console.log(q);


//得出余数，算出本月1号前面空多少
q += 2;
var qq = q % 7;
console.log(qq);



//算出上个月一共有多少天
var sy = 0;
    if(Month == 1){
        sy += 31;
    }else {
        switch (Month-1){
            case 1:
                sy += 31;
                break;
            case 2:
                if (wn(j)){
                    sy += 29;
                }else {
                    sy += 28;
                }
                break;
            case 3:
                sy += 31;
                break;
            case 4:
                sy += 30;
                break;
            case 5:
                sy += 31;
                break;
            case 6:
                sy += 30;
                break;
            case 7:
                sy += 31;
                break;
            case 8:
                sy += 31;
                break;
            case 9:
                sy += 30;
                break;
            case 10:
                sy += 31;
                break;
            case 11:
                sy += 30;
                break;
            case 12:
                sy += 31;
                break;
        }
    }

console.log(sy);


//当余数为0的时候进行判断

if(qq == 0){
    qq += 7
}




var nn1 = document.querySelector("#nn1");
//引入上个月的天数到html


    for (var p =sy - qq + 1 ; p <=sy ; p++){
         nn1.innerHTML += "<span class='n'>" + p + "</span>"
    }







//算出本月的天数
var by = 0;
switch (Month){
    case 1:
        by += 31;
        break;
    case 2:
        if (wn(j)){
            by += 29;
        }else {
            by += 28;
        }
        break;
    case 3:
        by += 31;
        break;
    case 4:
        by += 30;
        break;
    case 5:
        by += 31;
        break;
    case 6:
        by += 30;
        break;
    case 7:
        by += 31;
        break;
    case 8:
        by += 31;
        break;
    case 9:
        by += 30;
        break;
    case 10:
        by += 31;
        break;
    case 11:
        by += 30;
        break;
    case 12:
        by += 31;
        break;
}
console.log(by);

//引入本月的天数

//获取今天的日期
var rq = new Date().getDate();

for (var k=1 ; k<=by ; k++){
    if (k == rq){
        nn1.innerHTML += "<span class='n1'>" + rq + "</span>"
    }else {
        nn1.innerHTML += "<span>" + k + "</span>"
    }
}




//算出下个月的天数

//算出日历上一共能放多少天
var zts = 42;


    for (var gg=1 ; gg<=zts -qq -by ; gg++){
        nn1.innerHTML += "<span class='n'> " + gg + " </span>"
    }
